package IO;

import java.io.FileWriter;
import java.io.IOException;

public class Test5 {
   static String hw = "HelloWorld";

    public static void main(String[] args) {
        test1();
        test2();

    }
    public static void test1()  {
        FileWriter fw = null;

        try {
             fw = new FileWriter("a.txt",true);
            fw.write(hw);

        } catch (IOException e) {
            System.out.println("异常");
        }finally {
            try {
                if(fw!=null){
                    fw.close();
                }

            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
    public static void test2(){
        try(FileWriter fw = new FileWriter("a.txt",true);) {
            fw.write(hw);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
